Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overwrite label, width, or sas.format in xportr_type() #85

Merged
merged 6 commits into from
Apr 20, 2023

Conversation

EeethB
Copy link
Collaborator

@EeethB EeethB commented Apr 13, 2023

Fixes #75

The issue here was that coercing columns with as.character() or as.numeric() strips all attributes, not just the class attribute that we want to be rid of. I made a change to save attributes besides class (such as width, label, and format.sas), then restore those classes after coercion. I also wrote a test that checks for identical results whether xportr_type() is called at the beginning or end of a pipeline.

The function metacore::set_variable_labels() was also referenced in the original issue. I cannot find such a function in metacore, so I have not tested against it here. If it sets labels with an attribute like xportr does, this will fix it as well.

Should I ask the original issue filer to install this version for testing?

Please let me know if there's anything you want changed or included in this PR!

Fixes issue #75 by retaining column attributes (such as label). Tested
with `xportr_label()` only, not with `metacore::set_variable_labels()`
(is that even a real function?)
Now that `xportr_type()` is not overwriting column labels, applying it
before or after `xportr_label()` should make no difference
In general, setting the type for each column should retain each column's
attributes, such as label, width, and sas.format. These are set by other
xportr functions. However, in cases where a column in the input dataset
has a class already, such as a Date or a factor, this attribute should
be dropped from the column. If it is not, it causes an error
@codecov
Copy link

codecov bot commented Apr 13, 2023

Codecov Report

Merging #85 (6bcc015) into devel (833cca1) will increase coverage by 8.93%.
The diff coverage is 86.27%.

❗ Current head 6bcc015 differs from pull request most recent head d67cf2c. Consider uploading reports for the commit d67cf2c to get more accurate results

@@            Coverage Diff             @@
##            devel      #85      +/-   ##
==========================================
+ Coverage   66.00%   74.93%   +8.93%     
==========================================
  Files          10       10              
  Lines         350      375      +25     
==========================================
+ Hits          231      281      +50     
+ Misses        119       94      -25     
Impacted Files Coverage Δ
R/zzz.R 0.00% <0.00%> (ø)
R/utils-xportr.R 70.21% <84.61%> (+12.31%) ⬆️
R/format.R 84.37% <100.00%> (+6.59%) ⬆️
R/type.R 92.50% <100.00%> (+8.71%) ⬆️

... and 4 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bms63
Copy link
Collaborator

bms63 commented Apr 14, 2023

@EeethB can you have this go into the devel branch.

@elimillera can you make it so that branches that are merged into devel are deleted ?

@EeethB EeethB changed the base branch from main to devel April 14, 2023 14:22
tests/testthat/test-type.R Outdated Show resolved Hide resolved
Copy link
Collaborator

@bms63 bms63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is minor - but can we also put a quick blurb in the New.md file. Just good habit so we aren't doing this at the release.

@EeethB
Copy link
Collaborator Author

EeethB commented Apr 18, 2023

Comments have been added to NEWS.md

Copy link
Collaborator

@bms63 bms63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bms63
Copy link
Collaborator

bms63 commented Apr 18, 2023

@elimillera can you just once over this as well please??

@bms63 bms63 requested a review from elimillera April 18, 2023 16:09
@elimillera elimillera merged commit b4b8ab4 into devel Apr 20, 2023
@elimillera elimillera deleted the 75-xportr_dont-overwrite-labels-type branch April 20, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

xportr_type overwrites labels if comes after metacore::set_variable_labels or xportr::xpotr_label
3 participants